package com.ktgj.service.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.service.domain.ContractTerms;
import com.ktgj.service.service.IContractTermsService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 合同商务条款Controller
 * 
 * @author ruoyi
 * @date 2021-09-03
 */
@ControllerAdvice
@RestController
@RequestMapping("/terms")
public class ContractTermsController extends BaseController
{
    @Autowired
    private IContractTermsService contractTermsService;

    /**
     * 查询合同商务条款列表
     */
    @PreAuthorize(hasPermi = "service:terms:list")
    @GetMapping("/list")
    public TableDataInfo list(ContractTerms contractTerms)
    {
        startPage();
        List<ContractTerms> list = contractTermsService.selectContractTermsList(contractTerms);
        return getDataTable(list);
    }

    /**
     * 导出合同商务条款列表
     */
    @PreAuthorize(hasPermi = "service:terms:export")
    @Log(title = "合同商务条款", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ContractTerms contractTerms) throws IOException
    {
        List<ContractTerms> list = contractTermsService.selectContractTermsList(contractTerms);
        ExcelUtil<ContractTerms> util = new ExcelUtil<ContractTerms>(ContractTerms.class);
        util.exportExcel(response, list, "合同商务条款数据");
    }

    /**
     * 获取合同商务条款详细信息
     */
    @PreAuthorize(hasPermi = "service:terms:query")
    @GetMapping(value = "/{contractTermsId}")
    public AjaxResult getInfo(@PathVariable("contractTermsId") Long contractTermsId)
    {
        return AjaxResult.success(contractTermsService.selectContractTermsById(contractTermsId));
    }

    /**
     * 新增合同商务条款*/
    @PreAuthorize(hasPermi = "service:terms:add")
    @Log(title = "合同商务条款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContractTerms contractTerms)
    {
        return toAjax(contractTermsService.insertContractTerms(contractTerms));
    }

    /**
     * 修改合同商务条款*/
    @PreAuthorize(hasPermi = "service:terms:edit")
    @Log(title = "合同商务条款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContractTerms contractTerms)
    {
        return toAjax(contractTermsService.updateContractTerms(contractTerms));
    }

    /**
     * 删除合同商务条款*/
    @PreAuthorize(hasPermi = "service:terms:remove")
    @Log(title = "合同商务条款", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contractTermsIds}")
    public AjaxResult remove(@PathVariable Long[] contractTermsIds)
    {
        return toAjax(contractTermsService.deleteContractTermsByIds(contractTermsIds));
    }
}
